<?php declare(strict_types=1);
/**
 * @author      xianganyall <xianganyall@gmail.com>
 * @copyright   2023-2025 owner
 **/

namespace Srv\Conf\ConfModel;

use Srv\Libs\Frame\Conf;

final class EmailConfGroup
{
    private array $EmailConfGroupNameList           = [];       // EmailConf List groupName

    /**
     * @return array
     * getGroupNameList
     */
    public function getGroupNameList():array
    {
        $EmailConfList              = [];
        $groupNameList              = Conf::getGroupNameList(EmailConf::PREFIX);
        if(count($groupNameList) < 1) return $EmailConfList;
        foreach ($groupNameList as $groupName){
            $EmailConf              = $this->getByGroupName($groupName);
            if($EmailConf instanceof EmailConf) $EmailConfList[$groupName] = $EmailConf;
        }
        return $EmailConfList;
    }

    /**
     * @param string $groupName
     * @return EmailConf|null
     * getByGroupName
     */
    public function getByGroupName(string $groupName):?EmailConf
    {
        if(strlen($groupName) < 1) return null;
        if(isset($this->EmailConfGroupNameList[$groupName]) && $this->EmailConfGroupNameList[$groupName] instanceof EmailConf) return $this->EmailConfGroupNameList[$groupName];
        $confData                                   = Conf::getGroupList(EmailConf::PREFIX.$groupName.'.', false, true);
        if(count($confData) < 1) return null;
        $this->EmailConfGroupNameList[$groupName]   = new EmailConf($confData, $groupName);
        return $this->EmailConfGroupNameList[$groupName];
    }
}